home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Atari Mega Archive 1
/
Atari Mega Archive - Volume 1.iso
/
program
/
funnel.zoo
/
sources
/
dump.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-04-11
|
26KB
|
817 lines
/*##############################################################################
FUNNNELWEB COPYRIGHT
====================
FunnelWeb is a literate-programming macro preprocessor.
Copyright (C) 1992 Ross N. Williams.
Ross N. Williams
ross@spam.adelaide.edu.au
16 Lerwick Avenue, Hazelwood Park 5066, Australia.
This program is free software; you can redistribute it and/or modify
it under the terms of Version 2 of the GNU General Public License as
published by the Free Software Foundation.
This program is distributed WITHOUT ANY WARRANTY; without even the implied
warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See Version 2 of the GNU General Public License for more details.
You should have received a copy of Version 2 of the GNU General Public
License along with this program. If not, you can FTP the license from
prep.ai.mit.edu/pub/gnu/COPYING-2 or write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
Section 2a of the license requires that all changes to this file be
recorded prominently in this file. Please record all changes here.
Programmers:
RNW Ross N. Williams ross@spam.adelaide.edu.au
Changes:
07-May-1992 RNW Program prepared for release under GNU GPL V2.
##############################################################################*/
/******************************************************************************/
/* DUMP.C */
/******************************************************************************/
#include <ctype.h>
#include "style.h"
#include "as.h"
#include "clock.h"
#include "data.h"
#include "dump.h"
#include "misc.h"
/******************************************************************************/
#define DUMP_WIDTH (80)
/******************************************************************************/
/* The following advance declarations are required because of recursion. */
LOCAL void dm_ex P_((p_wf_t,p_ells_t));
/******************************************************************************/
LOCAL void centerln P_((p_wf_t,uword,int,char *));
LOCAL void centerln(p_wf,width,ch,s)
/* Writes string s in a line surrounded by character ch to specified width. */
/* Example: centerln(*,20,'-',"sloth") would write: "------ sloth -------" */
p_wf_t p_wf;
uword width;
int ch;
char *s;
{
uword sidebar,i;
char linet2[100];
/* Warning: linet2 can't be too big, or it will blow the Mac's limited */
/* stack space. Perhaps it should be put in the heap with a static pointer. */
as_cold(width>=5,"centerln: Width is too small.");
as_cold(width<=80,"centerln: Width is too large.");
as_cold(strlen(s) <= width-4,"centerln: Width is too narrow for string.");
/* Construct a sidebar string. */
sidebar=(width-strlen(s)-2)/2;
for (i=0;i<sidebar;i++) linet2[i]=ch;
linet2[sidebar]=EOS;
/* Now construct the result string. */
strcpy(linet1,linet2);
strcat(linet1," ");
strcat(linet1,s);
strcat(linet1," ");
strcat(linet1,linet2);
/* If the sidebar division removed a character, and the line is long enough */
/* for the user not to notice the imbalance, tack a character on the end. */
if (width>40 && strlen(linet1)==width-1)
{
uword len=strlen(linet1);
linet1[len]=ch;
linet1[len+1]=EOS;
}
/* Write the result string to the specified stream. */
wf_wl(p_wf,linet1);
}
/******************************************************************************/
LOCAL char * fontname P_((ubyte));
LOCAL char * fontname(font)
/* Given a font number, returns a pointer to a static string containing the */
/* name of the font. */
ubyte font;
{
switch (font)
{
case FT_NORM: return "Normal";
case FT_TITL: return "Title";
case FT_STIT: return "Small Title";
default : as_bomb("fontname: Font switch defaulted.");
}
/* Keep GCC warnings happy. */
as_bomb("fontname: Dropped out of switch.");
return "Failure";
}
/******************************************************************************/
LOCAL char * alignname P_((ubyte));
LOCAL char * alignname(align)
/* Given an alignment number, returns a pointer to a static string containing */
/* the name of the alignment. */
ubyte align;
{
switch (align)
{
case LR_LEFT: return "Left";
case LR_RIGH: return "Right";
case LR_CENT: return "Centre";
default : as_bomb("alignname: Alignment switch defaulted.");
}
/* Keep GCC warnings happy. */
as_bomb("alignnamename: Dropped out of switch.");
return "Failure";
}
/******************************************************************************/
EXPORT void dm_mem(p_wf,p_mem,length)
p_wf_t p_wf;
char *p_mem;
ulong length;
{
ubyte_ *p_base = (ubyte_ *) p_mem;
long len = length;
wf_wl(p_wf,"");
wf_wl(p_wf,"MEMORY DUMP OF MAPPED FILE");
wf_wl(p_wf,"==========================");
wf_wl(p_wf,"");
wf_wr(p_wf,"+-------------------------------------------------+------------------+\n");
wf_wr(p_wf,"| 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F | 0123456789ABCDEF |\n");
wf_wr(p_wf,"+-------------------------------------------------+------------------+\n");
while (len>0)
{/* Write a single line of 16 bytes per iteration. */
uword j;
wf_wr(p_wf,"| ");
for (j=0;j<16;j++)
if (j>=len)
wf_wr(p_wf," ");
else
{
char s[10];
sprintf(s,"%02X ",(unsigned int) p_base[j]);
wf_wr(p_wf,s);
}
wf_wr(p_wf,"| ");
for (j=0;j<16;j++)
if (j>=len)
wf_chr(p_wf,' ');
else
{
char ch=p_base[j];
/* DON'T use library function "isprint" - it is too loose. */
/* e.g. The vax "isprint" accepts top bit characters. */
if (!isascprn(ch)) ch='.';
wf_chr(p_wf,ch);
}
wf_wr(p_wf," |\n");
p_base+=16;
len-=16;
} /* End while */
wf_wr(p_wf,"+-------------------------------------------------+------------------+\n");
wf_wl(p_wf,"");
}
/******************************************************************************/
LOCAL void dm_byte P_((p_wf_t,ubyte));
LOCAL void dm_byte(p_wf,b)
/* Dumps a text representation of the given byte to the specified stream. */
p_wf_t p_wf;
ubyte b;
{
char t[10];
/* DON'T use library function "isprint" - it is too loose. */
/* e.g. The vax "isprint" accepts top bit characters. */
if (isascprn(b))
sprintf(t,"%c",(char) b);
else
sprintf(t,"<%03u>",(unsigned) b);
wf_wr(p_wf,t);
}
/******************************************************************************/
EXPORT void dm_lnls(p_wf)
p_wf_t p_wf;
{
wf_wl(p_wf,"");
centerln(p_wf,DUMP_WIDTH,'=',"Start of LINE LIST DUMP");
wf_wl(p_wf,"");
/*12345678901234567890123456789012345678901234567890123456789012345678901234567890*/
wf_wl(p_wf,"Globl Local| Text");
wf_wl(p_wf,"-----------+--------------------------------------------------------------------");
ls_fir(line_list);
while (TRUE)
{
ln_t *p_line;
char *p;
ls_nxt(line_list,PPV &p_line);
if (p_line==NULL) break;
sprintf(linet1,"%05lu %05lu| ",
(ulong) p_line->ln_global,
(ulong) p_line->ln_local);
wf_wr(p_wf,linet1);
for (p=p_line->ln_body.sc_first; p<=p_line->ln_body.sc_last; p++)
dm_byte(p_wf,*((ubyte_ *)p));
wf_wl(p_wf,"");
}
wf_wl(p_wf,"-----------+--------------------------------------------------------------------");
wf_wl(p_wf,"Globl Local| Text");
wf_wl(p_wf,"");
centerln(p_wf,DUMP_WIDTH,'=',"End of LINE LIST DUMP");
wf_wl(p_wf,"");
}
/******************************************************************************/
LOCAL void dm_sc P_((p_wf_t,p_sc_t));
LOCAL void dm_sc(p_wf,p_sc)
/* Dumps the specified scrap to the specified stream. */
p_wf_t p_wf;
p_sc_t p_sc;